﻿using System;
using System.IO;
using System.Windows;

using Microsoft.VisualStudio.NetworkEmulation.Properties;
using Microsoft.VisualStudio.QualityTools.NetworkEmulation;

namespace Microsoft.VisualStudio.NetworkEmulation
{
    internal static class NEUtilities
    {
        static NEUtilities()
        {
        }

        public static void DeployNEAPI()
        {
            const string networkEmulationAPIAssembly = "Microsoft.VisualStudio.QualityTools.NetworkEmulationAPI.dll";
            const string pathFormatString = @"API\{0}\" + networkEmulationAPIAssembly;
            string path = (NetworkEmulationInstaller.Is32BitOS) ?
                string.Format(pathFormatString, "x86") : string.Format(pathFormatString, "amd64");

            if (File.Exists(path))
            {
                try
                {
                    File.Copy(path, networkEmulationAPIAssembly, true);
                }
                catch (Exception)
                {
                    MessageBox.Show("The NetworkEmulationAPI could not be deployed.", "Error",
                        MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                MessageBox.Show("The NetworkEmulationAPI could not be located.", "Error",
                    MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }

        public static void ShowError(string message)
        {
            MessageBox.Show(message, Resources.ErrorMessageCaption, MessageBoxButton.OK, MessageBoxImage.Error);
        }
    }
}
